package com.lagou.module4.servlet;

import com.lagou.module4.service.StudentService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "RemoveServlet",urlPatterns = "/remove")
public class RemoveServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        int ID = Integer.parseInt(request.getParameter("ID"));
        StudentService studentService = new StudentService();
        int result = studentService.removeStudentService(ID);
        if (result==1){
            System.out.println("删除成功");
            response.setContentType("text/html;charset=utf-8");
            request.getSession().setAttribute("type","删除用户成功");
            response.sendRedirect("main.jsp");
        }else {
            System.out.println("删除失败");
            response.setContentType("text/html;charset=utf-8");
            request.getSession().setAttribute("type","删除用户失败");
            response.sendRedirect("main.jsp");
        }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request,response);
    }
}
